package Student.Test;

import Student.Dao.SubjectDao;
import Student.Entity.Subject;
import java.util.List;
import java.util.Scanner;

public class SubjectDaoTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        SubjectDao sd = new SubjectDao();
        while (true) {
            System.out.println("请选择您需要的操作：\n1、增加新课程\n2、修改课程\n3、分页显示课程\n" +
                    "4、根据课程编号查找课程\n5、删除课程\n0、退出");
            int chooce = input.nextInt();
            switch (chooce) {
                case 1:
                    System.out.println("请输入新课程的名称：");
                    String name = input.next();
                    System.out.println("请输入新课程的课程时长：");
                    int hour = input.nextInt();
                    System.out.println("请输入新课程的年纪编号：");
                    int gradeid = input.nextInt();
                    int add = sd.add(new Subject(name, hour, gradeid));
                    if (add > 0)
                        System.out.println("增加成功！");
                    else
                        System.out.println("增加失败！");
                    break;
                case 2:
                    System.out.println("请输入需要修改课程的编号：");
                    int id = input.nextInt();
                    System.out.println("请输入修改后课程的名称：");
                    String newname = input.next();
                    System.out.println("请输入修改后课程的课程时长：");
                    int newhour = input.nextInt();
                    System.out.println("请输入修改后课程的年纪编号：");
                    int newgradeid = input.nextInt();
                    int update = sd.update(new Subject(id, newname, newhour, newgradeid));
                    if (update > 0)
                        System.out.println("修改成功！");
                    else
                        System.out.println("修改失败！");
                    break;
                case 3:
                    System.out.println("请输入需要查看第几页：");
                    int page = input.nextInt();
                    System.out.println("请输入显示的行数：");
                    int line = input.nextInt();
                    List<Subject> list = sd.search(page, line);
                    for (int i = 0; i < list.size(); i++) {
                        System.out.println(list);
                    }
                    break;
                case 4:
                    System.out.println("请输入需要查询的课程编号：");
                    int f = input.nextInt();
                    Subject subject = sd.find(f);
                    if (subject != null)
                        System.out.println(subject);
                    else
                        System.out.println("未找到您输入的编号课程！");
                    break;
                case 5:
                    System.out.println("请输入需要删除的课程编号：");
                    int d = input.nextInt();
                    int delete = sd.delete(d);
                    if (delete == 1)
                        System.out.println("删除成功！");
                    else
                        System.out.println("删除失败！");
                    break;
                case 0:
                    System.out.println("退出！");
                    return;
            }
        }
    }
}
